package leet;


/**
 * Integer to Roman
 * 
 * @author zhujb
 *
 *         2017年8月31日
 */
public class Leet0012 {
	public static void main(String[] args) {

		System.out.println(intToRoman(3999));
		
	}

	public static String intToRoman(int num) {
		String rNumber = "";
		int[] aArray = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
		String[] rArray = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
		if (num < 1 || num > 3999) {
			rNumber = "-1";
		} else {
			for (int i = 0; i < aArray.length; i++) {
				while (num >= aArray[i]) {
					rNumber += rArray[i];
					num -= aArray[i];
				}
			}
		}
		return rNumber;
	}
}
